@extends('admin.layout.layout')
@section('css')
    <style>
        .td-manage a {
            margin: 0 5px;
        }

        .min-width .layui-form-select {
            width: 100px;
        }

        .layui-table-cell{
            text-align: center;
            height: auto;
            white-space: normal;
        }
        .layui-table img{
            max-width: 150px;
        }
    </style>
@endsection
@section('content')
    <div class="x-nav">
          <span class="layui-breadcrumb">
            <a >首页</a>
            <a >关键字管理</a>
            <a>
              <cite>关键字列表</cite></a>
          </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
           onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <button class="layui-btn" onclick="xadmin.open('添加关键字','{{asset('admin/keywords/create')}}',750,400)"><i class="layui-icon">添加</i>
                        </button>
                    </div>


                    <div class="layui-fluid">
                        <div class="layui-row layui-col-space15">
                            <div class="layui-col-md12">
                                <div class="layui-card">

                                    <div class="layui-card-body layui-table-body layui-table-main">
                                        <table id="table" lay-filter="test"></table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>


                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
<script >
    layui.use(['form', 'layer', 'table', 'laydate'],
        function () {
            $ = layui.jquery;
            var form = layui.form;
            var table = layui.table;
            var laydate = layui.laydate;
            var where = {};

            form.on('submit(sreach)', function (data) {
                where = data.field;
                console.log(where);
                table.reload('exportTable', {
                    where: where
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                return false;
            });
            laydate.render({
                elem: '#use_ticket_time'
                ,type: 'datetime'
                ,range: true //或 range: '~' 来自定义分割字符
            });
            form.render();
            table.render({
                elem: '#table'
                , id: 'exportTable'
                , limit: 15
                , limits: [15, 30, 60, 90]
                , loading: true
                , where: where
                , url:'{{asset('admin/keywords')}}' //数据接口
                , page: true //开启分页
                , cols: [[ //表头
                     {field: 'id', title: 'Id',width: '15%'},
                     {field: 'keyword', title: '关键字',width: '25%'},
                     {field: 'is_show', title: '是否显示',width: '25%'},
                     {field: 'created_at', title: '添加时间',width: '15%'},
                     {field: '', title: '操作', templet: function (d) {
                            let html = '';
                            html += '<span data-id="' + d.id + '" class="layui-btn layui-btn-sm layui-btn-danger del">删除</span>';
                            html += '<span class="layui-btn layui-btn-sm" style="background-color: #fdae72" onclick = "xadmin.open(\'编辑\',\'{{asset('admin/keywords')}}/' + d.id +'/edit'+'\',750,400)">编辑</span>';
                        return html;
                        },
                    },
                ]]
                , done: function (res, curr, count) {
                    $('.del').click(function (data) {
                        console.log(data);
                        let id = $(this).attr('data-id');
                        layer.confirm('你确定要删除此数据吗？', {
                            btn: ['确定', '取消'] //按钮
                        }, function () {
                            $.ajax({
                                url:'{{asset('admin/keywords')}}/' + id,
                                type:"delete",
                                contentType:"application/json",
                                dataType:"json",
                                success:function(res){
                                    if (res.code === 0) {
                                        layer.msg('删除成功', {icon: 1});
                                        table.reload('exportTable', {
                                            where: where
                                            , page: {
                                                curr: 1 //重新从第 1 页开始
                                            }
                                        });
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }

                                },
                                error:function(xhr,textstatus,thrown){
                                    layer.msg('删除失败', {icon: 2});
                                }
                            });
                        })
                    });
                }


            });
        });

</script>






    <script>
        /*用户-删除*/
        function member_del(obj, id) {
            layer.confirm('角色删除须谨慎，确认要删除吗？', function (index) {
                $.get('/admin/role/del?id='+id,function (re) {
                    if(re.status=='success'){
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                    }else{
                        layer.msg(re.msg,{icon:2,time:3000});
                    }
                });
            });
        }
    </script>
@endsection
